//***异常的学习***

class AgeException extends Exception {
    AgeException(String message) {
        super(message);
    }
}

class Person {
    int age;

    void setAge(int age) throws AgeException {
        if (age < 0 || age > 150) {
            throw new AgeException("输入的年龄不合法，年龄应该在 0 到 150 之间");
        }
        this.age = age;
    }
}

public class yichang {
    public static void main(String[] args) {
        Person person = new Person();
        try {
            person.setAge(-5);
            System.out.println("设置年龄成功，年龄是：" + person.age);
        } catch (AgeException e) {
            System.out.println("出问题：" + e.getMessage());
        } finally {
            System.out.println(" finally 块，一定会执行");
        }

        try {
            int[] numbers = {1, 2, 3};
            System.out.println(numbers[5]);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("出错，数组越界：" + e.getMessage());
        }
    }
}
